package render

import (
	"MetroBuilderGameJam/gameEngine/drawer"
	"MetroBuilderGameJam/gameEngine/geom"
	"MetroBuilderGameJam/gameEngine/utils"
	"MetroBuilderGameJam/world"
	"fmt"
	"github.com/hajimehoshi/ebiten/v2"
	"image/color"
)

func NewPassengerRenderer(d *drawer.Drawer, size float64, color color.Color) *Passenger {
	return &Passenger{
		drawer: d,
		size:   size,
		color:  color,
	}
}

type Passenger struct {
	drawer *drawer.Drawer
	size   float64
	color  color.Color
}

func (pr *Passenger) Draw(screen *ebiten.Image, p *world.Passenger, pos geom.Point, rotate geom.Radian) *utils.Figure {
	clr := pr.color
	switch p.Shape() {
	case world.StationTypeCircle:
		pr.drawer.FillCircle(screen, pos, pr.size, clr)
	case world.StationTypeSquare:
		pr.drawer.FillSquare(screen, pos, pr.size, rotate, clr)
	case world.StationTypeTriangle:
		pr.drawer.FillSimpleTriangle(screen, pos, pr.size, rotate, clr)
	case world.StationTypePentagon:
		pr.drawer.FillPentagon(screen, pos, pr.size, rotate, clr)
	case world.StationTypeStar:
		pr.drawer.FillStar(screen, pos, pr.size, rotate, clr)
	case world.StationTypeCross:
		pr.drawer.FillCross(screen, pos, pr.size, rotate, clr)
	default:
		fmt.Println(fmt.Errorf("unknown shape %d", p.Shape()))
	}

	return utils.NoFigure()
}

func (pr *Passenger) DrawForStation(screen *ebiten.Image, station *world.Station) {
	offset := geom.NewVec2(15, -15)
	distance := float64(12)
	for i, p := range station.Passengers() {
		pos := station.Position().AsVec2().Add(offset).Add(geom.NewVec2(float64(i%5)*distance+float64(i/5)*distance/2, float64(i/5)*distance))
		pr.Draw(screen, p, pos.AsPoint(), 0)
	}
}
